import validator from 'validator';
import { Schema } from 'mongoose';;
import { UserRoles, UserStatus, UserGenders } from '@/enums/userEnums';

export const UserSchema = new Schema({
  /**
   * 用户账户，登录用户名
   * */
  account: {
    type: String,
    unique: true,
    required: true,
    validate: (val: string) => validator.isEmail(val)
  },
  /**
   * 加密之后的密码
  */
  password: {
    type: String,
    required: true
  },
  /**
   * 用户生日
  */
  birthday: {
    type: Date,
    required: false
  },
  firstName: {
    type: String,
    required: false
  },
  lastName: {
    type: String,
    required: false
  },
  nickName: {
    type: String,
    require: false
  },
  phone: {
    type: String
  },
  about: {
    type: String
  },
  role: {
    type: String,
    required: true,
    default: UserRoles.guest,
    enum: Object.values(UserRoles),
  },
  status: {
    type: String,
    required: true,
    default: UserStatus.unreviewed,
    enum: Object.values(UserStatus),
  },
  gender: {
    type: String,
    required: true,
    default: UserGenders.female,
    enum: Object.values(UserGenders),
  },
  photos: [{
    type: Schema.Types.ObjectId,
    required: false,
    ref: 'photos'
  }]
}, {
  timestamps: true
});